home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / T-Z / Windoids.cpt / Windoid 1.7 / card_10516.txt < prev    next >
Text File  |  1989-04-19  |  10KB  |  249 lines

  1. -- card: 10516 from stack: in.7
  2. -- bmap block id: 10805
  3. -- flags: 0000
  4. -- background id: 10029
  5. -- name: 
  6. ----- HyperTalk script -----
  7. on ‚Ć
  8.   buttonFont
  9. end ‚Ć
  10.  
  11. on buttonFont
  12.   put empty into btnName
  13.   set cursor to arrow -- pointing cursor
  14.   -- see if the user selects a button:
  15.   wait until the mouseClick
  16.   set cursor to watch
  17.   put getButton(the clickLoc) into btnName
  18.   if btnName is not empty then -- then the user has
  19.     --chosen a button
  20.  
  21.     -- get all of its current properties:
  22.     put the textfont of btnName into font
  23.     put the textsize of btnName into size
  24.     put the textstyle of btnName into style
  25.     put the textalign of btnName into align
  26.  
  27.     -- now lock the screen, choose the Text tool,
  28.     -- and set defaults:
  29.     lock screen
  30.     choose text tool
  31.     set textfont to font
  32.     set textsize to size
  33.     set textstyle to style
  34.     set textalign to align
  35.  
  36.     -- bring up the Text Style dialog box:
  37.     type "t" with commandKey
  38.  
  39.     -- get the results of the Text Style dialog:
  40.     put the textfont into font
  41.     put the textsize into size
  42.     put the textstyle into style
  43.     put the textalign into align
  44.  
  45.     -- set the button accordingly:
  46.     set textfont of btnName to font
  47.     set textsize of btnName to size
  48.  
  49.     -- trap for multiple styles:
  50.     if the number of items of style > 1 then
  51.       put item 1 of style into style
  52.     end if
  53.     set textstyle of btnName to style
  54.     set textalign of btnName to align
  55.  
  56.     -- clean up:
  57.     choose browse tool
  58.     unlock screen
  59.   end if
  60. end buttonFont
  61.  
  62. function getButton clickPoint
  63. -- check all card buttons:
  64. repeat with i = 1 to the number of buttons
  65.   if clickPoint is within rect of card btn i then
  66.     return the name of btn i
  67.   end if
  68. end repeat
  69.  
  70. -- if it hasn't returned yet, then it wasn't a card button;
  71. -- check all background buttons:
  72. repeat with i = 1 to the number of background buttons
  73.   if clickPoint is within rect of bg btn i then
  74.     return the name of bg btn i
  75.   end if
  76. end repeat
  77. -- if it hasn't returned yet, it wasn't a button:
  78. return empty
  79. end getbutton
  80.  
  81.  
  82. -- part 13 (button)
  83. -- low flags: 00
  84. -- high flags: A003
  85. -- rect: left=19 top=212 right=243 bottom=106
  86. -- title width / last selected line: 0
  87. -- icon id / first selected line: 0 / 0
  88. -- text alignment: 1
  89. -- font id: 20
  90. -- text size: 12
  91. -- style flags: 0
  92. -- line height: 16
  93. -- part name: Change my text
  94. ----- HyperTalk script -----
  95. on mouseUp
  96.   set name of me to "Yow"
  97.   wait 30
  98.   set name of me to "Change my text"
  99. end mouseUp
  100.  
  101.  
  102.  
  103. -- part contents for background part 11
  104. ----- text -----
  105. ‚Ä¢ with excellent refinements By Clifford Guren
  106. __________________________________________________________
  107.  
  108. ‚Ä¢ Setting the text properties of buttons ‚Äîthe textFont, textSize, textAlign, and textStyle properties‚Äî is currently accomplished via the grace of the message box.   You must type a sequence of the set command as follows:
  109.  
  110. set textFont of button "Sample Button" to Helvetica
  111. set textSize of btn "Sample Button" to 14
  112. set textStyle of btn "Sample Button" to bold
  113. set textAlign of btn "Sample Button" to center
  114.  
  115. This article describes a script that lets you set the text properties of buttons using the same Text Style dialog box used to set the text properties of fields and paint text.  In addition, the script uses some of the new features in HyperCard 1.2.1 , including the within operator and many of the new synonyms.
  116.  
  117. The script has only two parts, (1) a message called buttonFont that performs most of the work and (2) a function called getButton that returns the name of a button the user chooses with a click. 
  118.  
  119. When you call buttonFont, the basic algorithm is as follows:
  120.  
  121. ‚Ä¢  ButtonFont changes the cursor to the Arrow cursor to indicate that you should choose a button.  It then waits for you to click the mouse.  
  122. ‚Ä¢  After you click the mouse, buttonFont calls the function getButton, which returns the name of the button you have chosen.  If getButton returns the empty string, you did not click a button, so buttonFont exits.
  123. ‚Ä¢  ButtonFont then gets the current text properties of the chosen button and saves them as default settings.
  124. ‚Ä¢  Next, buttonFont locks the screen, chooses the Text tool, and sets the text properties to the default values.  It then brings up the Text Style dialog box with each text property set to the value of the default settings 
  125. (that is, the text properties of the button).  You can then use the dialog box to make any changes to the text properties.  Note that textHeight is not a property of buttons, so its value is not used by buttonFont.
  126. ‚Ä¢  After you finish with the Text Style dialog, buttonFont reads the new values of the text properties.  It then sets the text properties of the button to these values.  Note that if you canceled the Text Style dialog box, the values are just those of the default setting, so the button's text properties are not changed.
  127. ‚Ä¢  Finally, buttonFont chooses the Browse tool and unlocks the screen.  
  128.  
  129. Since no mouse events are sent while the buttonFont message is running, the function getButton uses HyperCard 1.2.1's new within operator to determine whether you clicked a location on the screen that is within the region of a button:
  130.  
  131. ‚Ä¢  getButton takes one argument, the point where you last clicked (the clickLoc).
  132. ‚Ä¢  It then goes through all the card buttons using within to see if the point is inside the rect of any of these buttons.  If so, it returns the name of the card button.
  133. ‚Ä¢  If getButton did not return, it then goes through all the background buttons using within to determine if the point is inside the rect of any of these buttons.  If so, it returns the name of the background button.
  134. ‚Ä¢  Finally, if getButton did not return, it returns the empty string because you did not click a button.
  135.  
  136. To get the most use of the buttonFont message, you will probably want to copy it, and getButton, into the script of your Home stack.  There are several ways that you might call it.  One is to assign it to a function key.  For example, putting the following code in your Home stack lets the F7 key invoke the message:
  137.  
  138. on functionKey whatKey
  139.    if whatKey is 7 then
  140.      buttonFont
  141.    else
  142.      --any other function key assignments
  143.    end if
  144. end functionKey
  145.  
  146. If you don't have function keys, you can assign buttonFont to the key command Option-T (to relate it to Command-T, the key command that brings up the Text Style dialog box).  Because HyperTalk cannot trap for a single key press, you will have to press Option-T and then the Return key to send the message.  This works best if the property Blind Typing from the User Preferences card is set to true so that the message box does not have to be visible when you type Option-T.  The following code lets Option-T invoke buttonFont (where Option-T is the character ‚Ć):
  147.  
  148. on ‚Ć
  149.    buttonFont
  150. end ‚Ć
  151.  
  152. Finally, here are a few things to note about using the buttonFont message:
  153.  
  154. ‚Ä¢  Buttons in the following script cannot have more than one textStyle property; for example, they can be bold or condense, but not bold and condense.  The Text Style dialog box, however, allows users to choose more than one text style because fields and paint text can have more than one style.  If users forget and set more than one style for a button, buttonFont only uses the first (or topmost) style.
  155. ‚Ä¢  The text properties of buttons do not affect the text that is displayed when a button shows an icon.
  156. ‚Ä¢  The appearance of a given font depends on the fonts currently installed in the System.  For example, if a user sets a button's font to Times but does not have Times in his System, an automatic font substitution will occur.
  157. ‚Ä¢  With HyperCard 1.2.1, stacks can be write-protected.  If a stack is write-protected, none of the choices in the Text Style dialog box are active, so you can't actually change the text properties of the button.
  158. ‚Ä¢  To cancel the buttonFont message before you actually select a button, just click where there is no button (or use Command-period).
  159. _________________________________________________________
  160.  
  161. ‚Ä¢ buttonFont message and its auxiliary function for 
  162. HyperCard Version 1.2.1
  163.  
  164. on buttonFont
  165.   put empty into btnName
  166.   set cursor to arrow -- pointing cursor 
  167.   -- see if the user selects a button:
  168.   wait until the mouseClick
  169.   set cursor to watch
  170.   put getButton(the clickLoc) into btnName
  171.   if btnName is not empty then -- then the user has
  172.   --chosen a button
  173.  
  174.   -- get all of its current properties:
  175.     put the textfont of btnName into font
  176.     put the textsize of btnName into size
  177.     put the textstyle of btnName into style
  178.     put the textalign of btnName into align
  179.  
  180.     -- now lock the screen, choose the Text tool, 
  181.     -- and set defaults:
  182.     lock screen
  183.     choose text tool
  184.     set textfont to font
  185.     set textsize to size
  186.     set textstyle to style
  187.     set textalign to align
  188.  
  189.     -- bring up the Text Style dialog box:
  190.     type "t" with commandKey
  191.  
  192.     -- get the results of the Text Style dialog:
  193.     put the textfont into font
  194.     put the textsize into size
  195.     put the textstyle into style
  196.     put the textalign into align
  197.  
  198.     -- set the button accordingly:
  199.     set textfont of btnName to font
  200.     set textsize of btnName to size
  201.  
  202.     -- trap for multiple styles:
  203.     if the number of items of style > 1 then
  204.       put item 1 of style into style
  205.     end if
  206.     set textstyle of btnName to style
  207.     set textalign of btnName to align
  208.  
  209.     -- clean up:
  210.     choose browse tool
  211.     unlock screen
  212.   end if
  213. end buttonFont
  214.  
  215. function getButton clickPoint
  216.   -- check all card buttons:
  217.   repeat with i = 1 to the number of buttons
  218.     if clickPoint is within rect of card btn i then
  219.       return the name of btn i
  220.     end if
  221.   end repeat
  222.  
  223.   -- if it hasn't returned yet, then it wasn't a card button;
  224.   -- check all background buttons:
  225.   repeat with i = 1 to the number of background buttons
  226.     if clickPoint is within rect of bg btn i then
  227.       return the name of bg btn i
  228.     end if
  229.   end repeat
  230.   -- if it hasn't returned yet, it wasn't a button:
  231.   return empty
  232. end getbutton
  233. Ô£ø
  234.  
  235. -- part contents for background part 17
  236. ----- text -----
  237. Four Button Properties In Search Of A Script
  238.  
  239. -- part contents for background part 18
  240. ----- text -----
  241.  
  242.  
  243.  
  244.  
  245. ‚Ä¢ by Jim Palmer
  246.  
  247. -- part contents for background part 19
  248. ----- text -----
  249. volume 1 ‚Ä¢  number  7  ‚Ä¢  card 4  ‚Ä¢